package com.example.miscontactos.Entidades;

import java.util.ArrayList;

import android.content.ContentResolver;
import android.database.Cursor;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.CommonDataKinds.Email;

public class Mail 
{
	public String direccionMail;
	
	public Mail()
    {
        super();
    }
    
    public Mail(String direccionMail) 
    {
        super();
        this.direccionMail = direccionMail;
    }
	
	public static ArrayList<Mail> GetMailsContacto(ContentResolver cr, String id)
	{
		 ArrayList<Mail> emails = new ArrayList<Mail>();
	                
        /*Cursor cursor = cr.query(			
                CommonDataKinds.Email.CONTENT_URI, 
                null, 
                CommonDataKinds.Phone.CONTACT_ID +" = ?", 
                new String[]{id}, null);*/
		 
		 Cursor emailCursor = cr.query(Email.CONTENT_URI, null,
                 Email.CONTACT_ID + " = " + id, null, null);

        while (emailCursor.moveToNext())
        {
        	Mail mail = new Mail();
        	//mail.direccionMail = emailCursor.getString(emailCursor.getColumnIndex(CommonDataKinds.Email.ADDRESS));
        	mail.direccionMail = emailCursor.getString(emailCursor.getColumnIndex(Email.DATA));
            emails.add(mail);
        } 

        emailCursor.close();
        return(emails);
	}
}
